/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package net.tygzs.minerpg.lib;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author thtTNT
 */
public class FileLib
{

    public static void copyFile(File oldPath, File newPath)
    {
        try
        {
            int bytesum = 0;
            int byteread;
            File oldfile = oldPath;
            if (oldfile.exists())
            { //文件存在时 
                InputStream inStream = new FileInputStream(oldPath); //读入原文件 
                FileOutputStream fs = new FileOutputStream(newPath);
                byte[] buffer = new byte[1444];
                int length;
                while ((byteread = inStream.read(buffer)) != -1)
                {
                    bytesum += byteread; //字节数 文件大小 
                    fs.write(buffer, 0, byteread);
                }
                inStream.close();
            }
        } catch (FileNotFoundException ex)
        {
            Logger.getLogger(FileLib.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex)
        {
            Logger.getLogger(FileLib.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
